<#include "../common/_layout.html" />
<@head title="微信自动回复管理编辑">
<style type="text/css">
	.cll {
		background-color: #ddd;
	}
</style>
</@head>
<@layout menu='/wechatrobot'>
<section class="content-header">
	<h1>
		${pageTitleBread.department!pageTitleBread.default!}
	</h1>
	<ol class="breadcrumb">
		<li><a href="javascript:void(0);" onclick="location.href='${ctx}${pageTitleBread.breadHomeMethod!}'">首页</a></li>
		<li><a href="javascript:void(0);" onclick="location.href='${ctx}${pageTitleBread.url!}'">${pageTitleBread.pageTitle!}</a></li>
		<li class="active">${pageTitleBread.nowBread!}</li>
	</ol>
</section>
<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<div class="box">
				<form action="${ctx}/wechatrobot/save" method="post" role="form">
					<legend>编辑</legend>
					<input type="hidden" name="wechatRobot.id" id="wechatRobot.id" value="${wechatRobot.id!}">
                    <input type="hidden" name="wechatRobot" id="wechatRobot" value="${wechatRobot.id!}">
					<div class="form-group">
						<input type="hidden" type="number" class="form-control" id="wechatRobot.wechat_info_id" name="wechatRobot.wechat_info_id" placeholder="微信ID" value="${wechatRobot.wechat_info_id!}">
					</div>
					<div class="form-group">
						<label for="wechatRobot.reply_type">自动回复类型</label>
						<select id="wechatRobot.reply_type" name="wechatRobot.reply_type" class="form-control" autofocus="autofocus"    onchange="show_or_hide(this.value)">
							<option value = "0" <#if wechatRobot.reply_type??&&wechatRobot.reply_type==0>selected="selected"</#if>>关注时回复</option>
							<option value = "1" <#if wechatRobot.reply_type??&&wechatRobot.reply_type==1>selected="selected"</#if>>默认回复，一般用户回复帮助性内容</option>
							<option value = "2" <#if wechatRobot.reply_type??&&wechatRobot.reply_type==2>selected="selected"</#if>>按关键字回复</option>
						</select>
					</div>
					<small class="help-block" <#if !reply_type_msg??>style="display:none" </#if>><#if reply_type_msg??>${reply_type_msg!}</#if></small>
					<div class="form-group">
						<label for="wechatRobot.rule_name">规则名</label>
						<input type="text" class="form-control" id="wechatRobot.rule_name" name="wechatRobot.rule_name" placeholder="规则名" value="${wechatRobot.rule_name!}"autofocus="autofocus">
					</div>
					<small class="help-block" <#if !rule_name_msg??>style="display:none" </#if>><#if rule_name_msg??>${rule_name_msg!}</#if></small>
					<div class="form-group" id="keywords" hidden>
						<label for="wechatRobot.keywords">关键字</label>
                        <textarea id="wechatRobot.keywords" name="wechatRobot.keywords" class="form-control" rows="5"autofocus="autofocus">${wechatRobot.keywords!}</textarea>
					</div>
					<small class="help-block" <#if !keywords_msg??>style="display:none" </#if>><#if keywords_msg??>${keywords_msg!}</#if></small>
                    <button id="save" type="submit" class="btn btn-primary">保存</button><button type="button" id="cancle" class="btn btn-cancle" onclick="location.href='${ctx}/wechatrobot?id=${wechatRobot.wechat_info_id!}'">返回</button>
                </form>
				<#if page??>
					<div id="wechatRobotMedia" hidden>
						<#include "../wechatrobotmedia/index.html"/>
					</div>
				</#if>
			</div>
		</div>
	</div>
</section>
</@layout>
<@scripts>

<script type="text/javascript" src="${ctx}/adminlte/plugins/layer/layer.js"></script>
<script type="text/javascript" src="/js/list.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
	    if ($('#wechatRobot').val()==null||$('#wechatRobot').val()==""){
	        $("#wechatRobotMedia").hide();
		}else{
            $("#wechatRobotMedia").show();
		}

        document.getElementById('wechatRobot.reply_type').onchange()

        if($("#type").val()==5){
            if($("#list").val()>7){
                $("#add").attr("disabled",true);
            }
        }else{
            if($("#list").val()>0){
                $("#add").attr("disabled",true);
            }
        }
    });
    function openmodal(url) {
        if($("#type").val()==5){
            url=url+"&flag=1";
        }else{
            url=url+"&flag=0";
        }
        $.post(url, {}, function(str){
            layer.open({
                type: 1,
                area: ["1024px", "768px"],
                content: str //注意，如果str是object，那么需要字符拼接。
            });
        });
    }

	function show_or_hide(s) {
        if(s!="2"){
            $("#keywords").hide();
            document.getElementById('wechatRobot.keywords').value=null;
        }else{
            $("#keywords").show();
        }
    }
</script>
</@scripts>